import { galGetListService as getBa } from '../axios/api/ba'
import { galGetListService as getGal } from '../axios/api/galgame'

export default class DataManager {
    static manager: DataManager;


    datas: Array<dataDict> = [];

    public constructor() {
        DataManager.manager = this;
    }

    public static async get(id: string) {
        return DataManager.manager.getData(id);
    }

    private async getData(id: string) {
        const { datas } = this;
        const cur = datas.find(u => u.id == id)?.data;

        if (!cur) {
            switch (id) {
                case 'baData':
                    var curData = await getBa();
                    datas.push({
                        id: id,
                        data: curData,
                    });
                    return curData;
                case 'galData':
                    var curData = await getGal();
                    datas.push({
                        id: id,
                        data: curData,
                    });
                    return curData;
            }
        } else {
            return cur;
        }
    }

}

interface dataDict {
    id: string,
    data: object,
}